﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using MyLibrary.ThreeLayer.DataAccess.MetaData;

namespace MyLibrary.ThreeLayer.DataAccess.MetaData
{
    public class MetaDataFactory
    {
        private static readonly IDictionary<string, MappingCollection> _mappingCollectionList = new Dictionary<string, MappingCollection>();

        public static MappingField GetMappingField(PropertyInfo p)
        {
            MappingField field = new PropertyField(p);
            if (field.HasNoMapAttribute)
                return null;
            return field;
        }

        public static MappingCollection GetMappingCollection(Type type)
        {
            if(_mappingCollectionList.ContainsKey(type.FullName))
                return _mappingCollectionList[type.FullName];
            else
            {
                MappingCollection collection = new MappingCollection(type);
                _mappingCollectionList.Add(type.FullName, collection);
                return collection;
            }
        }

        public static string GetMappingTable(Type type)
        {
            return GetMappingCollection(type)._TableName;
        }
    }
}
